<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平时成绩管理系统-学生管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-student"
     style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">学号</label>
        <div class="layui-input-block">
            <input type="text" name="studentId" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="studentName" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">班级</label>
        <div class="layui-input-block">
            <select name="clazzId" id="clazzId"></select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-inline">
            <input type="text" name="studentImg" lay-verify="required" placeholder="请上传图片" autocomplete="off"
                   class="layui-input">
        </div>
        <button style="float: left;" type="button" class="layui-btn" id="layuiadmin-upload-img">上传图片</button>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">选择性别</label>
        <div class="layui-input-block">
            <input type="radio" name="studentGender" value="0" title="男" checked>
            <input type="radio" name="studentGender" value="1" title="女">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-student-submit" id="LAY-user-student-submit" value="确认">
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<!--班级option选项模板-->
<script id="optionClazzId" type="text/html">
    {{#  layui.each(d.data, function(index, clazz){  }}
    <option value="{{clazz.clazzId}}">
        {{clazz.clazzYear}}级 {{clazz.clazzName}}
    </option>
    {{#  }); }}
    {{#  if(d.data.length === 0){ }}
    无数据
    {{#  } }}
</script>
<script>
    layui.config({
        base: '../../../layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'upload', 'laytpl'], function () {
        let $ = layui.$
            , setter = layui.setter
            , laytpl = layui.laytpl
            , form = layui.form
            , upload = layui.upload;

        /*加载班级信息*/
        $(function () {
            $.ajax({
                url: setter.baseUrl + '/clazz/ins',
                dataType: "json",
                type: "get",
                contentType: 'application/json',
                xhrFields: {
                    withCredentials: true
                },
                success: function (res) {
                    if (res.code === 200) {
                        let getTpl = optionClazzId.innerHTML
                            , view = document.getElementById('clazzId');
                        laytpl(getTpl).render(res, function (html) {
                            view.innerHTML = html;
                        });
                        form.render(); //更新全部
                    } else {
                        layer.msg("失败");
                    }

                },
                error: function (e) {
                    layer.msg("失败");
                }
            });
        });

        upload.render({
            elem: '#layuiadmin-upload-img'
            , url: setter.baseUrl + '/uploadImg'
            , accept: 'images'
            , method: 'post'
            , acceptMime: '/static/img/*'
            , done: function (res) {
                $(this.item).prev("div").children("input").val(res.data)
            }
        });
    })
</script>
</body>
</html>
